package com.ly.cloud.service.impl;

import com.ly.cloud.dto.SeparateClassRuleDto;
import com.ly.cloud.entity.SeparateClassRulePo;
import com.ly.cloud.exception.CloudException;
import com.ly.cloud.mapper.SeparateClassRuleMapper;
import com.ly.cloud.service.SeparateClassRuleService;
import com.ly.cloud.utils.BeanCopyUtils;
import com.ly.cloud.vo.SeparateClassRuleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description: 分班规则
 * @Author: pengshiqng
 * @Date: Create in 2018/12/24
 */

@Service
public class SeparateClassRuleServiceImpl implements SeparateClassRuleService {


    @Autowired
    private SeparateClassRuleMapper separateClassRuleMapper ;

    /**
    * @Description: 查询所有
    * @Author: pengshiqing
    * @CreateDate: 2018/12/24
    */
    @Override
    public List<SeparateClassRuleVo> findAll() {
        try {
            List<SeparateClassRulePo> poList = separateClassRuleMapper.selectList(null);
            //把po对象转换成vo对象
            List<SeparateClassRuleVo> polist = BeanCopyUtils.copyListProperties(poList, SeparateClassRuleVo.class);
            return polist;
        } catch (Exception e){
            e.printStackTrace();
            throw new CloudException("查询失败!", e);
        }
    }

    /**
    * @Description: 更新
    * @Author: pengshiqing
    * @CreateDate: 2018/12/24
    */
    @Override
    @Transactional
    public void update(List<SeparateClassRuleDto> list) {
        try {
            for (SeparateClassRuleDto dto : list){
                //把dto对象转换成po对象
                SeparateClassRulePo po = BeanCopyUtils.copyBeanProperties(dto, SeparateClassRulePo.class);
                separateClassRuleMapper.updateById(po);
            }
        } catch (Exception e){
            e.printStackTrace();
            throw new CloudException("更新失败!", e);
        }
    }
}
